from yisheng_user.models import yiShengUser
from django.views.decorators.csrf import csrf_exempt
from django.http import JsonResponse
from django.forms.models import model_to_dict
import json
from django.db import connection
@csrf_exempt
def test(request):
    query_reslut = yiShengUser.objects.raw("select * from yisheng_user")
    list = []
    for q in query_reslut:
        list.append(model_to_dict(q))
    return JsonResponse({'result': json.dumps(list)})

'''
import MySQLdb
conn=MySQLdb.connect(host="localhost",user="root",passwd="sa",db="mytable")
cursor=conn.cursor()
cursor.close()
conn.close() 
'''
@csrf_exempt
def testAdd(request):
    cursor = connection.cursor()
    # cursor.execute("insert into yisheng_contract(username) VALUES ('15807532342')")
    cursor.execute("SELECT yc.* FROM yisheng_user AS yu, yisheng_contract AS yc WHERE yu.username = yc.username")
    raw = cursor.fetchall()
    cursor.close()
    return JsonResponse({'code': json.dumps(raw)})